package com.livestocksolutions.intent;

import com.livestocksolutions.LivestockSolutions;
import com.livestocksolutions.R;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.widget.Toast;

/**
 * Display settings and other miscellaneous data.
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 19 March 2013
 */
public class SettingsActivity extends PreferenceActivity {
	@Override
	@SuppressWarnings("deprecation")
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        findPreference("deleteData").setOnPreferenceClickListener(new OnPreferenceClickListener(){
        	public boolean onPreferenceClick(Preference preference) {
				new AlertDialog.Builder(SettingsActivity.this)
			    .setTitle(getResources().getString(R.string.settings_deleteData))
			    .setMessage(getResources().getString(R.string.setting_delete_confirm))
			    .setPositiveButton(getResources().getString(R.string.menu_delete), new DialogInterface.OnClickListener() {
			        public void onClick(DialogInterface dialog, int which) { 
			        	LivestockSolutions.deleteAll();
			        	Toast.makeText(SettingsActivity.this, getResources().getString(R.string.message_dataDeleted), Toast.LENGTH_SHORT).show();
			        }
			     })
			     .setNegativeButton(getResources().getString(R.string.message_cancel), new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which){}})
			     .show();
				return true;
			}
        });
        
        findPreference("about").setOnPreferenceClickListener(new OnPreferenceClickListener(){
			public boolean onPreferenceClick(Preference preference) {
				new AlertDialog.Builder(SettingsActivity.this)
			    .setTitle(getResources().getString(R.string.settings_about))
			    .setMessage(getResources().getString(
			    		R.string.settings_aboutDescription,
			    		getResources().getString(R.string.app_version),
			    		getResources().getString(R.string.app_authors),
			    		getResources().getString(R.string.app_date),
			    		getResources().getString(R.string.app_name),
			    		getResources().getString(R.string.app_uses)))
			    .setNeutralButton(getResources().getString(R.string.message_close), new DialogInterface.OnClickListener() {
			        public void onClick(DialogInterface dialog, int which) { 
			            // do nothing
			        }
			     })
			     .show();
				return true;
			}
        });
    }
}
